<?php
/**
 * Created by PhpStorm.
 * User: mojie126
 * Date: 2017/7/5 0005
 * Time: 下午 13:37
 */

namespace app\index\controller;


class TruckController extends Base
{
	public function index($id, $type)
	{
		if ($type == "m") {
			$type = 0;
		} elseif ($type == "s") {
			$type = 1;
		}
		$where = [
			"userid" => session("uid"),
			"torrentid" => $id,
			"type" => $type
		];
		$check = db("rss")->where($where)->count("id");
		$insert = array_merge($where, ["addtime" => nowtime(), "type" => $type]);
		if ($check <= 0) {
			$res = db("rss")->insert($insert);
			if ($res) {
				jsonReturn(1, "添加成功");
			} else {
				jsonReturn(0, "添加失败");
			}
		} else {
			$res = db("rss")->where($where)->delete();
			if ($res) {
				jsonReturn(2, "删除成功");
			} else {
				jsonReturn(0, "删除失败");
			}
		}
	}
}